package com.loong.data.controller.forehead;

import com.loong.common.mvc.BaseForeheadController;
import com.loong.common.param.BaseIdParam;
import com.loong.common.rest.Result;
import com.loong.common.validator.group.CommonValidate;
import com.loong.data.common.forehead.param.GoodsAndPageForeheadParam;
import com.loong.data.handler.GoodsHandler;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Description: 处理前端商品请求的controller
 * @Author: 刘群
 * @Date: 2020/11/12 17:39
 */
@RestController
@RequestMapping("forehead/data/goods")
public class GoodsForeheadController extends BaseForeheadController {

    @Resource
    private GoodsHandler goodsHandler;

    /**
     * 根据商品id查询商品
     * @param param 商品id
     * @return 响应的结果
     */
    @PostMapping("findById")
    public Result findGoodsById(@RequestBody @Validated({CommonValidate.class}) BaseIdParam param){
        return handlerExecutor.execute(() -> goodsHandler.foreheadFindGoodsById(param));
    }

    /**
     * 分页查询es中的商品信息
     * @param param 商品和分页封装的查询参数
     * @return 响应的结果
     */
    @PostMapping("pageQuery/GoodsList")
    public Result pageQueryGoods(@RequestBody GoodsAndPageForeheadParam param){
        return handlerExecutor.execute(() -> goodsHandler.foreheadPageQueryGoods(param));
    }
}
